package com.ridu.project.beshid.api;

import lombok.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/17.
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class GeneralResponse<T> {
    //GeneralResponse封装了分页对象
    private Status status = Status.SUCCESS;
    private String message;
    private List<T> rows = new ArrayList();// 分页数据集合
    private T data;
    private long total;// 数据总条数

    public static GeneralResponse success(String message) {
        GeneralResponse generalResponse = new GeneralResponse();
        generalResponse.setMessage(message);
        return generalResponse;
    }

    public static<T> GeneralResponse success(T t) {
        GeneralResponse generalResponse = new GeneralResponse();
        generalResponse.setData(t);
        return generalResponse;
    }

    public static GeneralResponse error(String message) {
        GeneralResponse generalResponse = new GeneralResponse();
        generalResponse.setMessage(message);
        generalResponse.setStatus(Status.FAILED);
        return generalResponse;
    }
}
